//
//  NSDictionary+Log.m
//  07-掌握-多值参数和中文输出
//
//  Created by 文顶顶 
//  Copyright © 2015年 文顶顶. All rights reserved.
//

#import <Foundation/Foundation.h>

@implementation NSDictionary (Log)

-(nonnull NSString *)descriptionWithLocale:(nullable id)locale
{
    NSMutableString *string = [NSMutableString string];
    
    //以{开头
    [string appendString:@"\n{\n"];
    
    [self enumerateKeysAndObjectsUsingBlock:^(id  __nonnull key, id  __nonnull obj, BOOL * __nonnull stop) {
        
        [string appendFormat:@"\t%@",key];
        [string appendString:@":"];
        [string appendFormat:@"%@,\n",obj];
    }];
    
    //以}结尾
    [string appendString:@"}"];
    
    NSRange range =  [string rangeOfString:@"," options:NSBackwardsSearch];
    if (range.location != NSNotFound) {
        [string deleteCharactersInRange:range];
    }
    
    return string;
}

@end

@implementation NSArray(Log)

-(nonnull NSString *)descriptionWithLocale:(nullable id)locale
{
    NSMutableString *string = [NSMutableString string];
    
    //以[开头
    [string appendString:@"["];
    [self enumerateObjectsUsingBlock:^(id  __nonnull obj, NSUInteger idx, BOOL * __nonnull stop) {
       
        [string appendFormat:@"%@,\n",obj];
    }];
    
    //以]结尾
    [string appendString:@"]\n"];
    
    NSRange range =  [string rangeOfString:@"," options:NSBackwardsSearch];
    if (range.location != NSNotFound) {
        [string deleteCharactersInRange:range];
    }
    
    return string;
}


@end
